import request from "@/utils/request";
import { httpsUrl } from "@/utils/httpsUrl";

const Http = {
  Post(url: string, data: any, responseType?: any) {
    return request<any>({
      url: url.indexOf("jeecg-boot") != -1 ? url : httpsUrl[url],
      method: "post",
      data: JSON.stringify(data),
      responseType: responseType,
    });
  },

  Get(url: string, data?: any, responseType?: any) {
    return request<any>({
      url: url.indexOf("jeecg-boot") != -1 ? url : httpsUrl[url],
      method: "get",
      params: data,
      headers: {
        "Content-Type": "multipart/form-data",
      },
      responseType: responseType,
    });
  },

  upload(file: File) {
    const formData = new FormData();
    formData.append("file", file);
    formData.append("module", "MEMBER_SERVICE");
    return request<any, FileInfo>({
      url: "/member/wx/upload",
      method: "post",
      data: formData,
      headers: {
        "Content-Type": "multipart/form-data",
      },
    });
  },
};

export interface FileInfo {
  /** 文件名 */
  name: string;
  /** 文件路径 */
  url: string;
}

export default Http;
